from django_filters.rest_framework import FilterSet
from django_filters.filters import *
from .models import *


class ProtocolTypeFilterSet(FilterSet):
    name = CharFilter(lookup_expr="contains")
    type = CharFilter(lookup_expr="contains")
    start_time = DateFilter(
        field_name="create_time", lookup_expr="gte", label="开始日期"
    )
    end_time = DateFilter(field_name="create_time", lookup_expr="lt", label="结束日期")

    class Meta:
        model = ProtocolType
        fields = ["name", "type", "product", "status", "start_time", "end_time"]


class ProtocolFieldFilterSet(FilterSet):
    name = CharFilter(lookup_expr="contains")
    sdx = CharFilter(lookup_expr="contains")
    desc = CharFilter(lookup_expr="contains")
    start_time = DateFilter(
        field_name="create_time", lookup_expr="gte", label="开始日期"
    )
    end_time = DateFilter(field_name="create_time", lookup_expr="lt", label="结束日期")

    class Meta:
        model = ProtocolField
        fields = [
            "name",
            "sdx",
            "desc",
            "product",
            "protocol",
            "status",
            "isjx",
            "istl",
            "issx",
            "start_time",
            "end_time",
        ]
